﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class registerForm : Form
    {
        public registerForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void button1_Click_1(object sender, EventArgs e)
        {
            //提取文本框的元素
            string userText = textBox1.Text;
            string passWord = textBox2.Text;
            string passWord1 = textBox3.Text;

            //判断用户名是不是空的

            if (userText.Length == 0)
            {
                MessageBox.Show("用户名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //判断密码和确认密码是否相等
                if (passWord.Equals(passWord1))
                {
                    var sql = string.Format("insert into Users(Username,Password) values('{0}','{1}')", userText, passWord);

                    int a = DbHelper.Operate(sql);

                    
                   
                    if (a != 0)
                    {
                        MessageBox.Show("添加成功！", "提示", MessageBoxButtons.OK);
                        this.Close();
                    }
                   
                }
                else
                {
                    MessageBox.Show("密码不一致！添加失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
          

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
